class DashboardController < ApplicationController
  def index
    @loadbox = Loadbox.last
	@user_setting = UserSetting.last
    @power_consumption = PowerLog.last.power_consumption
	@utility_setting = UtilitySetting.last
	@outlet_status = OutletStatus.all
	session[:statuses] = outlets
  end
  
  def outlets
  	scalar = 1
  	bin = 0
  	@outlet_status.each do |outlet|
  		if outlet.status == true
  			bin = bin + scalar
  		end
  		scalar = scalar*10
  	end
  	return bin
  end
  
  def point
    t = UtilityFunctions.current_time
    x = [2012,1,Time.now.hour,t[0],t[1]]
	p = PowerLog.get_power_consumption
	g = GreenSimulation.get_green_power
	price = UtilitySetting.get_price
	m = price*(p - g)
	if m <= 0 
		m = 0
	end
	
	@points = [x,p,g,m]
	
	
    respond_to do |format|
      format.json { render json: @points}
    end
  end
  
  def outlet_display
    @outlet_status = OutletStatus.all
    @statuses = session[:statuses]
    if session[:statuses] != outlets
    	respond_to do |format|
  	  		format.html  
      		format.json { render json: @outlet_status}
    	end
    end
    
  	
  end

  
end

      